<?php

namespace Test;

use SplFixedArray;
use SplMinHeap;
use SplQueue;
use SplStack;

class Test
{

    public function index()
    {
        $this->spl_stack();
        $this->spl_queue();
        $this->spl_minheap();
        $this->spl_fixedArray();
    }

    // 栈
    public function spl_stack()
    {
        // 先进后出
        $splstack = new SplStack();
        $splstack->push('data1<br>');
        $splstack->push('data2<br>');

        echo $splstack->pop();
        echo $splstack->pop();
    }

    // 队列
    public function spl_queue()
    {
        $splqueue = new SplQueue();
        $splqueue->enqueue('data3<br>');
        $splqueue->enqueue('data4<br>');

        echo $splqueue->dequeue();
        echo $splqueue->dequeue();
    }


    // 最小堆
    public function spl_minheap()
    {
        $splMinHeap = new SplMinHeap();
        $splMinHeap->insert('data5<br>');
        $splMinHeap->insert('data6<br>');

        echo $splMinHeap->extract();
        echo $splMinHeap->extract();
    }

    // 固定长度的数组
    public function spl_fixedArray()
    {
        $splFixedArray = new SplFixedArray(10);
        $splFixedArray[0] = 11;
        $splFixedArray[9] = 22;

        var_dump($splFixedArray);
    }
}
